package dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;

public class Conection {
    
    private EntityManagerFactory emf;
    protected EntityManager em;
    
    protected void OpenConection(){
        try{
            emf = Persistence.createEntityManagerFactory("SUE-AGORAVAIPU");
            em = emf.createEntityManager();
            em.getTransaction().begin();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Erro ao abrir conexão - "+e.getMessage());
        }
    }
    
    protected void CloseConection(){
        try{
            em.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Erro ao fechar conexão - "+e.getMessage());
        }
    }
    
}//CLASS
